package com.gcsoftware.web.mapper;

import com.gcsoftware.beans.SysUser;
import com.gcsoftware.web.utils.StringUtils;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.web.bind.annotation.ModelAttribute;

import java.util.List;

import static com.gcsoftware.configs.AppConstants.Sys.SYS_STR_SPLIT;

/**
 * SQL语句
 * @author czp
 * date 2018-05-05
 */
public class AutoSql {
    public String updateUserInfo(@ModelAttribute final SysUser sysUser) {
        String sql = new SQL() {
            {
                UPDATE("T_DEMO_SYS_USER");

                if (sysUser.getC_user_name() != null) {
                    SET("C_USER_NAME = #{c_user_name}");
                }
                if (sysUser.getC_user_pwd() != null) {
                    SET("C_USER_PWD = #{c_user_pwd}");
                }
                if (sysUser.getC_pwd_question() != null) {
                    SET("C_PWD_QUESTION = #{c_pwd_question}");
                }
                if (sysUser.getC_pwd_answer() != null) {
                    SET("C_PWD_ANSWER = #{c_pwd_answer}");
                }

                WHERE("C_SEQ_ID = #{c_seq_id}");
            }
        }.toString();
        return sql;
    }

    public String getSysLogs(@Param("action")final String action, @Param("time")final String time,
                             @Param("sord")final String sord) {
        List<String> actions = StringUtils.StringSplit(action, SYS_STR_SPLIT.getValue());
        List<String> times = StringUtils.StringSplit(time, SYS_STR_SPLIT.getValue());
        for (String a : actions) {
            System.out.println(a);
        }
        for (String t : times) {
            System.out.println(t);
        }
        return "SELECT * FROM T_DEMO_SYS_LOG";
    }
}
